package kgame5.pbe.atlantic.manager {
import kgame5.k2d.Camera2D;
import kgame5.k2d.MouseInput2D;
import kgame5.pbe.engine.PBEConst;
import kgame5.pbe.engine.core.IAnimatedObject;

import flash.display.DisplayObject;
import flash.display.Sprite;

/**
	 * @author max
	 * 2010-12-13
	 * 注意，摄像机需要单独设置
	 * 游戏视图管理器,
	 * 注意Vector3D是左手坐标，2D时之用x,y,z，不要用内积外积
	 * -----------X
	 * |
	 * |
	 * |
	 * Y
	 * 
	 * 
	 */
	public class View2DManager implements IAnimatedObject {
		
		
		private var mc_theRoot:Sprite;//最外层容器
		private var mc_game:Sprite;//游戏,当清除的时候会被删除
		
		public var camera:Camera2D;//这个可被外部访问，设置摄像机的视野和世界大小,直接暴露被外部访问并不是很好
		
		private var mouseInput:MouseInput2D;//拖拽屏幕用的,也可以用来定位点击打的是屏幕的哪个位置
		
		
		private var aLayer:Array;//
		
		public function View2DManager(p_mc_theRoot:Sprite) {
			mc_theRoot=p_mc_theRoot;
			
		}

		public function start():void{
			mc_game=new Sprite();
			mc_theRoot.addChild(mc_game);
			
			//摄像机
			camera =new Camera2D(mc_game);
			camera.setViewSize(760, 600);
			camera.setWorldSize(760,600);
			
			//鼠标拖拽屏幕
			mouseInput=new MouseInput2D(mc_game,camera);
			
			//各个图层
			aLayer=[];
			for(var i:int=0;i<PBEConst.MAX_LAYER;i++) {
				var mc_layer:Sprite=new Sprite();
				mc_game.addChild(mc_layer);
				aLayer.push(mc_layer);
			}
			
		}
		public function clear():void{
			mc_theRoot.removeChild(mc_game);
			mc_game=null;
			aLayer=null;
		}
		
		public function onFrame(deltaTime : Number) : void {	
			camera.update();
		}
		
		public function addNode(mc:DisplayObject,layerID:int):void{
			(aLayer[layerID] as Sprite).addChild(mc);
			
			
		}
		
		//没做安全性检查，出错会报错的
		public function removeNode(mc:DisplayObject,layerID:int):void{
			(aLayer[layerID] as Sprite).removeChild(mc);
			
		}
		
		//取得特定图层，这个是用来添加二外效果用的
		public function getLayer(layerID:int):Sprite{
			return aLayer[layerID];
		}
		
		//取得全部,直接原因是拍照使用
		public function getRoot():Sprite{
			return mc_game;
		}
	}//end of class
}

//public function init(mc_c:Sprite,viewWidth:int,viewHeight:int,worldWidth:int,worldHeight:int):void{
//			
//			this.mc_game=mc_c;
//		
//			//摄像机
//			camera =new Camera2D(mc_c);
//			camera.setViewSize(viewWidth, viewHeight);
//			camera.setWorldSize(worldWidth,worldHeight);
//			
//			//鼠标拖拽屏幕
//			mouseInput=new MouseInput2D(mc_c,camera);
//			
//			//各个图层
//			aLayer=[];
//			for(var i:int=0;i<PBEConst.MAX_LAYER;i++) {
//				var mc_layer:Sprite=new Sprite();
//				mc_c.addChild(mc_layer);
//				aLayer.push(mc_layer);
//			}
//		}